package com.example.mapp;

import com.example.entity.authority.SystemRole;
import com.example.ext.entity.ExtSystemRole;
import com.example.mapp.buildSql.SystemRoleMappSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by youkun on 2017/8/13.
 */
@Mapper
public interface SystemRoleMapp {

    @SelectProvider(type = SystemRoleMappSql.class,method = "queryList")
    public List<SystemRole> queryList(SystemRole systemRole)throws Exception;

    @Select(" select id,role_name,role_describe from system_role where id=#{id}")
    public SystemRole queryById(@Param("id") String id) throws Exception;

    @Select(" select id,role_name,role_describe from system_role where role_name=#{roleName}")
    public SystemRole queryByName(ExtSystemRole systemRole) throws Exception;

    @Insert(" insert into system_role (role_name,role_describe,use_state,role_type) value (#{roleName},#{roleDescribe},#{useState},#{roleType})")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    public int add(ExtSystemRole systemRole) throws Exception;

    @Update(" update system_role set role_name =#{roleName},role_describe =#{roleDescribe} where id=#{id}")
    public int update(SystemRole systemRole) throws Exception;

    @Delete(" delete from system_role where id=#{id} ")
    public int deleteSystemRoleById(String id) throws Exception;

    @Select(" select * from system_role where role_type=#{roleTypeId} and use_state='1'")
    List<SystemRole> queryByRoleTypeId(String roleTypeId)throws Exception;

    @Select(" select a.* from system_role as a " +
            "inner join system_role_type_relation as b on a.id = b.role_id  " +
            "inner join party_role_type as c on b.role_type_id = c.party_type " +
            "where c.party_type = #{partyType} and a.use_state='1' ")
    List<SystemRole> queryByPartyIdList(String partyType)throws Exception;

}
